<template>
  <div class="wrap">
    <div class="search">
      <input type="text" v-model="username" @keyup.enter="query" placeholder="请输入订单名称" />
      <img src="../assets/search.png" @click="query" alt />
    </div>
    <div class="list">
      <div class="dateBox">
        <div class="date" @click="dateState = true">
          <p>订单日期</p>
          <p v-if="date">{{date}}</p>
        </div>
      </div>
      <!-- <van-index-bar> -->
        <van-pull-refresh v-model="refreshing" @refresh="onRefresh">
         
            <div class="item" v-for="(item,idx) in list" :key="idx" @click="next(item)">
              <div class="left">
                <img :src="item.avatar" :onerror="defaultImg" alt />
                <div>
                  <p>{{item.username}}</p>
                  <span>订单数：{{item.total}}</span>
                </div>
              </div>
              <img src="../assets/right.png" class="right" alt />
            </div>
         <van-empty description="暂无数据" v-if="state==1" />
        </van-pull-refresh>
      <!-- </van-index-bar> -->
    </div>
    <van-popup v-model="dateState" position="bottom">
      <van-datetime-picker
        v-model="createDate"
        type="date"
        @confirm="dateConfirm"
        @cancel="dateCancel"
        cancel-button-text="全部"
      />
    </van-popup>
  </div>
</template>
<style>
  .van-pull-refresh__track{
    height: 60vh;
  }
</style>
<style lang="scss" scoped>
.tab {
  display: flex;
  width: 9.2rem;
  margin: 20px auto 0;
  border-bottom: 1px solid #e5e5e5;
  justify-content: space-around;
  p {
    font-size: 0.48rem;
    color: #555;
    line-height: 1.066667rem;
  }
  .active {
    color: #3fd9c9;
  }
}
.search {
  background: #eeeded;
  height: 1.066667rem;
  width: 9.2rem;
  margin: 0.306667rem auto 0.4rem;
  border-radius: 0.266667rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
  input {
    border: none;
    outline: none;
    background: transparent;
    margin-left: 15px;
  }
  img {
    width: 0.533333rem;
    height: 0.533333rem;
    display: block;
    margin-right: 15px;
  }
}
.dateBox {
  display: flex;
  justify-content: flex-end;
  margin-bottom: 0.4rem;
  .date {
    padding: 0 0.5rem;
    height: 0.613333rem;
    background: #3fd9c9;
    border-radius: 0.306667rem;
    margin-right: 0.4rem;
    display: flex;
    justify-content: space-around;
    color: #fff;
    font-size: 0.306667rem;
    align-items: center;
    p:nth-of-type(2) {
      margin-left: 0.5rem;
    }
  }
}
.item {
  height: 1.6rem;
  border-bottom: 1px solid #e5e5e5;
  width: 9.2rem;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  .left {
    display: flex;
    align-items: center;
    img {
      width: 1.013333rem;
      height: 1.013333rem;
      display: block;
      border-radius: 50%;
      margin-right: 0.186667rem;
      object-fit: cover;
    }
    p {
      color: #555;
      font-size: 0.4rem;
      text-align: left;
    }
    span {
      color: #999;
      font-size: 0.25rem;
      text-align: left;
      display: block;
    }
  }
  .right {
    display: block;
    width: 0.4rem;
    height: 0.4rem;
  }
}
>>> .van-index-bar__index {
  font-size: 12px;
  line-height: 20px;
}
</style>
<script>
import { getProxyBizList } from "@/utils/interface";
import { formatDate } from "@/utils/tools";
import { Empty } from 'vant';

export default {
  components:{
    Empty
  },
  data() {
    return {
      defaultImg: 'this.src="' + require("../assets/user2.png") + '"',
      FirstPin: [
        "A",
        "B",
        "C",
        "D",
        "E",
        "F",
        "G",
        "H",
        "J",
        "K",
        "L",
        "M",
        "N",
        "P",
        "Q",
        "R",
        "S",
        "T",
        "W",
        "X",
        "Y",
        "Z"
      ],
      list: [],
      username: "",
      dateState: false,
      date: "",
      createDate: new Date(),
      loading: false,
      finished: true,
      refreshing: false,
      state:0
    };
  },
  created() {
    let date = sessionStorage.getItem('mysend-date')
    date?(this.date=date):''
    document.title = "发货订单";
    this.getList(this.username, this.date);
  },
  methods: {
    next(item) {
      this.$router.push({
        path: "mySendDetail",
        query: { info: JSON.stringify(item) }
      });
    },
    getList(username, createDate) {
      getProxyBizList({ username, createDate }).then(res => {
        console.log(res.data);
        this.list = res.data.data;
        if(this.list.length==0){
          this.state = 1
        }
        this.loading = false;
        this.refreshing = false;
        this.finished = true;
      });
    },
    query() {
      this.getList(this.username, this.date);
    },
    dateConfirm(e) {
      this.date = formatDate(e);
      sessionStorage.setItem('mysend-date',this.date)
      this.dateState = false;
      this.getList(this.username, this.date);
    },
    dateCancel() {
      this.date = "";
      sessionStorage.setItem('mysend-date',"")
      this.dateState = false;
      this.getList(this.username, this.date);
    },
    onRefresh(){
      this.finished = false;
      this.loading = true;
      this.getList(this.username, this.date);
    },
  }
};
</script>